package org.example.schoolbus.controller;
import org.example.schoolbus.entity.ResultBody;
import org.example.schoolbus.service.InfoEditingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@RestController
@RequestMapping("/Information")
@CrossOrigin(origins = "*")
public class InfoEditingController {
    @Autowired
    private InfoEditingService infoEditingService;
    @RequestMapping("/InfoEditing")
    public  ResultBody InfoEditing(@RequestBody Map<String,Object> map) {
        if(map.get("username")==null||map.get("usersex")==null||map.get("userbirthday")==null||map.get("useraddress")==null||map.get("userphone")==null||map.get("useremail")==null)
        {
            return new ResultBody(404,"填写信息不完整",false);
        }
        String username = map.get("username").toString();
        String usersex = map.get("usersex").toString();
        String userbirthday = map.get("userbirthday").toString();
        String useraddress = map.get("useraddress").toString();
        String userphone = map.get("userphone").toString();
        String useremail = map.get("useremail").toString();
        if(infoEditingService.InfoEditing(username,usersex,userbirthday,useraddress,userphone,useremail)>0) {
            //信息正确填写
            return new ResultBody(200,"信息编辑成功",true);
        }
        else
            return new ResultBody(400,"信息编辑失败",false);

    }

}
